import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
import { AllExceptionsFilter } from './common/exceptions/base.exception.filter';
import { HttpExceptionFilter } from './common/exceptions/http.exception.filter';
import { generateDocument } from './doc';

// declare const module: any;

async function bootstrap() {
  // 热更新
  // if (module.hot) {
  //   module.hot.accept();
  //   module.hot.dispose(() => app.close());
  // }
  const app = await NestFactory.create(AppModule);
  // 统一响应体格式;
  app.useGlobalInterceptors(new TransformInterceptor());
  // 异常过滤器
  app.useGlobalFilters(
    // 全局异常过滤
    new AllExceptionsFilter(),
    // http异常过滤
    new HttpExceptionFilter(),
  );

  // 创建文档
  generateDocument(app);

  await app.listen(3000);
}
bootstrap();
